<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="ss" uri="/WEB-INF/tld/ss.tld"  %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html>
  <head>
    <base href="<%=basePath%>">
    <%@include file="../common/common.jsp" %>
    <script type="text/javascript" src="js/jquery.form.js"></script>
	<style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
  </head>
  
  <body>
    <form id="frm" action="user/saveUser.do" method="post" class="definewidth m20">
		<input type="hidden" name="action" value="${param.action }" />
		<input type="hidden" name="id" value="${param.id }" />
	    <table class="table table-bordered table-hover definewidth m10">
	        <tr>
	            <td width="18%" class="tableleft">用户名	</td>
	            <td><input type="text" name="user_name" id="user_name" value="${user.user_name}"/></td>
	        </tr>
	        <tr>
	            <td class="tableleft">密码</td>
	            <td><input type="password" name="password" id="password" value="${user.user_password }"/></td>
	        </tr>
	        <tr>
	            <td class="tableleft">确认密码</td>
	            <td><input type="password" name="password2" id="password2" value="${user.user_password }"/></td>
	        </tr>
	        <tr>
	            <td class="tableleft">真实姓名</td>
	            <td><input type="text" name="real_name" value="${user.real_name}"/></td>
	        </tr>	        
	        <tr>
	            <td class="tableleft">角色</td>
	            <td>
	            	<ss:role id="role" name="role" value="${user.role }"/>
	            </td>
	        </tr>
	        
	        <tr>
	            <td class="tableleft"></td>
	            <td>
	                <button type="button" onclick="save()" class="btn btn-primary" type="button">保存</button>&nbsp;&nbsp;
	                <button type="button" class="btn" onclick="frameElement.api.close();">关闭</button>
	            </td>
	        </tr>
	    </table>
	</form>
  </body>
</html>
<script>
    function save(){
    	var name=$("#user_name");
    	if(name.val()==''){
    		alert("用户名不能为空");name.focus();return;
    	}
    	var p1=$("#password");
    	var p2=$("#password2");
    	if(p1.val()!=p2.val()){
    		alert("两次密码输入不一致,请重新输入");return;
    	}
		var str=$('#frm').formSerialize();
    	$.post("user/saveUser.do",str,function (a,b){
    		if(b=='success'){
    			var msg=a.msg;
    			alert(msg)
    			if(msg=='保存成功'){
    				var api = frameElement.api;
					var w = api.opener;
					w.document.frm.submit();
					api.close();
    				//window.location.href="user/queryUser.do";
    			}
    		}
    	});
    }
</script>